/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: Pegasus  Date: 2019-02-13 Time: 23:07
 */
import {Login,Cache,OffWork,WHSKMenuMain,CreateFtpTimer,Alinarg,ButtonRight} from "./Actions"
import {FetchStatus} from "../../../configuration/RequestConfiguration"

/**
 * 登录
 * @param state
 * @param action
 * @returns {{fetchStatus: *}}
 */
export const onLogin = (state = {}, action) => {
  switch (action.type) {
    case Login: {
      switch (action.status) {
        case FetchStatus.Start: {
          return {...state, fetchStatus: action.status}
        }
        case FetchStatus.Success: {
          return {...action.json, fetchStatus: action.status}
        }
        default: {
          return {...state, fetchStatus: action.status}
        }
      }
    }
  }
  return state
};

/**
 * 缓存
 * @param state
 * @param action
 * @returns {{fetchStatus: *}}
 */
export const onGetCache = (state = {}, action) => {
    switch (action.type) {
        case Cache: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state, fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json, fetchStatus: action.status}
                }
                default: {
                    return {...state, fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

export const onAlinarg = (state = {}, action) => {
    switch (action.type) {
        case Alinarg: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state, fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json, fetchStatus: action.status}
                }
                default: {
                    return {...state, fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

export const onButtonRight = (state = {}, action) => {
    switch (action.type) {
        case ButtonRight: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state, fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json, fetchStatus: action.status}
                }
                default: {
                    return {...state, fetchStatus: action.status}
                }
            }
        }
    }
    return state
};



/**
 * 下班
 * @param state
 * @param action
 * @returns {{fetchStatus: *}}
 */
export const onOffWork = (state = {}, action) => {
    switch (action.type) {
        case OffWork: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state, fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json, fetchStatus: action.status}
                }
                default: {
                    return {...state, fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


/**
 * 主页红点
 * @param state
 * @param action
 * @returns {{fetchStatus: *}}
 */
export const onWHSKMenuMain = (state = {}, action) => {
    switch (action.type) {
        case WHSKMenuMain: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state, fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json, fetchStatus: action.status}
                }
                default: {
                    return {...state, fetchStatus: action.status}
                }
            }
        }
    }
    return state
};

export const onCreateFtpTimer = (state = {}, action) => {
    switch (action.type) {
        case CreateFtpTimer: {
            switch (action.status) {
                case FetchStatus.Start: {
                    return {...state, fetchStatus: action.status}
                }
                case FetchStatus.Success: {
                    return {...action.json, fetchStatus: action.status}
                }
                default: {
                    return {...state, fetchStatus: action.status}
                }
            }
        }
    }
    return state
};


